/**
 * basicOverview.js
 * 筛选器action, 描述包含筛选器页面中的用户条件筛选行为
 *
 * created by xurui
 * version 1.0.0
 * 2016年03月31日
 */

import { create } from './asyncActionCreator';
import { SUBJECT_URL, GRADE_URL, COUNTY_URL, SCHOOL_URL  } from '../../../constants/API'


/**
 * 获取用户选择城市列表
 * @param  {[type]} selectedItem [description]
 * @return {[type]}              [description]
 */
export const SELECTED_CITY = 'selected city';
export const selectedCity = (selectedItem) => ({
	type:SELECTED_CITY,
	payload:{
		selectedItem
	}
});
export const GET_CITY_OPTIONS = 'get city options';
export const getCityOptions = (options) => ({
	type:GET_CITY_OPTIONS,
	payload:{
		options
	}
});
/**
 * 地域选择，选择区县
 * @type {String}
 */
export const SELECTED_COUNTY = 'selected county',
			 GET_COUNTY_OPTIONS_REQUEST = 'get county options request',
			 GET_COUNTY_OPTIONS_SUCCESS = 'get county options success',
			 GET_COUNTY_OPTIONS_FAILURE = 'get county options failure';
/**
 * 获取用户选择列表
 * @param  {[type]} options      [description]
 * @return {[type]}              [description]
 */
export const selectedCounty = (selectedItem) => ({
	type:SELECTED_COUNTY,
	payload:{
		selectedItem
	}
});
/**
 * 异步获取区县可选项
 * @param  {[type]} options [description]
 * @return {[type]}         [description]
 */
export const getCountyOptionsRequest = () => ({
	type:GET_COUNTY_OPTIONS_REQUEST,
	payload:{}
});
export const getCountyOptionsSuccess = (options) => ({
	type:GET_COUNTY_OPTIONS_SUCCESS,
	payload:{
		options
	}
});
export const getCountyOptionsFailure = (errorMessage) => ({
	type:GET_COUNTY_OPTIONS_FAILURE,
	payload:{
		errorMessage
	}
});
export const getCountyOptions = (params,onSuccess) => {
	return create(`${COUNTY_URL}/${params}`,
		getCountyOptionsRequest,
		getCountyOptionsSuccess,
		getCountyOptionsFailure,
		undefined,
		onSuccess)
};
/**
 * 地域选择，选择学校
 * @type {String}
 * @param {object}  获取回来的数据
 * @return {object} Action描述
 */
export const SELECTED_SCHOOL = 'selected school',
			 GET_SCHOOL_OPTIONS_REQUEST = 'get school options request',
			 GET_SCHOOL_OPTIONS_SUCCESS = 'get school options success',
			 GET_SCHOOL_OPTIONS_FAILURE = 'get school options failure';
/**
 * 获取用户选择学校列表
 * @param  {[type]} selectedItem [description]
 * @return {[type]}              [description]
 */
export const selectedSchool = (selectedItem) => ({
	type:SELECTED_SCHOOL,
	payload:{
		selectedItem
	}
});
/**
 * 异步获取用户列表
 * @param  {[type]} options [description]
 * @return {[type]}         [description]
 */
export const getSchoolOptionsRequest = () => ({
	type:GET_SCHOOL_OPTIONS_REQUEST,
	payload:{}
});
export const getSchoolOptionsSuccess = (options) => ({
	type:GET_SCHOOL_OPTIONS_SUCCESS,
	payload:{
		options
	}
});
export const getSchoolOptionsFailure = (errorMessage) => ({
	type:GET_SCHOOL_OPTIONS_FAILURE,
	payload:{
		errorMessage
	}
});
export const getSchoolOptions = (params,onSuccess) => {
	return create(`${SCHOOL_URL}/${params}`,
		getSchoolOptionsRequest,
		getSchoolOptionsSuccess,
		getSchoolOptionsFailure,
		undefined,
		onSuccess)
};
/**
 * 选择科目，异步请求科目数据
 * @type {String}
 * @param {object} 获取回来的数据
 * @return { object} [Action描述]
 */
export const GET_SUBJECT_REQUEST = 'get subject request',
		 	 GET_SUBJECT_SUCCESS = 'get subject success',
			 GET_SUBJECT_FAILURE = 'get subject failure';
export const getSubjectRequest = () => ({
	type:GET_SUBJECT_REQUEST,
	payload:{}
});
export const getSubjectSuccess = (options) => ({
	type:GET_SUBJECT_SUCCESS,
	payload:{
		options
	}
});
export const getSubjectFailure = (errorMessage) => ({
	type:GET_SUBJECT_FAILURE,
	payload:{
		errorMessage
	}
});
//请求科目数据
export const getSubjectOptions = () => {
	return create(SUBJECT_URL,
		getSubjectRequest,
		getSubjectSuccess,
		getSubjectFailure)
}
//获取用户选择列表
export const SELECTED_SUBJECT = 'selected subject';
export const selectedSubject = (selectedItems) => ({
	type:SELECTED_SUBJECT,
	payload:{
		selectedItems
	}
});
/**
 * 选择年级，异步请求年级数据
 * @type {String}
 * @param {object} 获取回来的数据
 * @return { object} [Action描述]
 */
export const GET_GRADE_REQUEST = 'get grade request',
			 GET_GRADE_SUCCESS = 'get grade success',
			 GET_GRADE_FAILURE = 'get grade failure';
export const getGradeRequest = () => ({
	type:GET_GRADE_REQUEST,
	payload:{}
});
export const getGradeSuccess= (options) => ({
	type:GET_GRADE_SUCCESS,
	payload:{
		options
	}
});
export const getGradeFailure = (errorMessage) => ({
	type:GET_GRADE_FAILURE,
	payload:{
		errorMessage
	}
});
//请求科目数据
export const getGradeOptions = () => {
	return create(GRADE_URL,
				getGradeRequest,
				getGradeSuccess,
				getGradeFailure)
		};
//获取用户选择列表
export const SELECTED_GRADE = 'selected grade';
export const selectedGrade = (selectedItems) => ({
	type:SELECTED_GRADE,
	payload:{
		selectedItems
	}
});
/**
 * 选择日期范围，异步获取日期相关数据
 * @type {String}
 * @param {object} 获取日期范围
 * @return {object} [Action描述]
 */
export const SET_DATE_RANGE = 'set date range';
export const setDateRange = (dateRange) => ({
	type:SET_DATE_RANGE,
	payload:{
		dateRange
	}
});

/**
 * 重置筛选器
 * @type {String}
 */
export const RESET = 'reset all filter';
export const reset = () => ({
	type: RESET,
	payload: {}
});










